package com.cvit.service;

import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cvit.dao.VregionMapper;
import com.cvit.dao.Vscience1Mapper;
import com.cvit.dao.VscienceMapper;
import com.cvit.model.ExcelBean;
import com.cvit.model.Vregion;
import com.cvit.model.Vscience;
import com.cvit.model.Vscience1;
import com.cvit.utils.ExcelUtil;

@Service
public class HomePageService {

	@Autowired
	VregionMapper vregionMapper;
	@Autowired
	VscienceMapper vscienceMapper;
	@Autowired
	Vscience1Mapper vscience1Mapper;
	
	/**
	 * 地区人数统计
	 * */
	public List<Vregion> regionStatistics() {
		List<Vregion> list=vregionMapper.selectAll();
		return list;
	}
	/**
	 * 理科人数统计
	 * */
	public List<Vscience> scienceStatistics() {
		List<Vscience> list=vscienceMapper.selectAll();
		return list;
	}
	/**
	 * 文科人数统计
	 * */
	public List<Vscience1> science1Statistics() {
		List<Vscience1> list=vscience1Mapper.selectAll();
		return list;
	}
	/**
	 * 导出Excel		地区人数统计
	 * */
	public XSSFWorkbook exportExcelInfo(String vregion) throws InvocationTargetException, ClassNotFoundException, IntrospectionException, ParseException, IllegalAccessException {  
		List<Vregion> list= vregionMapper.selectAll();
	    List<ExcelBean> excel=new ArrayList<>();
	    Map<Integer,List<ExcelBean>> map=new LinkedHashMap<>();
	    XSSFWorkbook xssfWorkbook=null;
	    excel.add(new ExcelBean("地区名称","region",0));
	    excel.add(new ExcelBean("人数","num",0));
	    map.put(0, excel);
	    String sheetName = vregion;
	    xssfWorkbook = ExcelUtil.createExcelFile(Vregion.class, list, map, sheetName);
	    return xssfWorkbook;
	}
	
	/**
	 * 导出Excel		理科人数统计
	 * */
	public XSSFWorkbook VscienceExportExcelInfo(String VscienceExport) throws InvocationTargetException, ClassNotFoundException, IntrospectionException, ParseException, IllegalAccessException {  
		List<Vscience> list= vscienceMapper.selectAll();
	    List<ExcelBean> excel=new ArrayList<>();
	    Map<Integer,List<ExcelBean>> map=new LinkedHashMap<>();
	    XSSFWorkbook xssfWorkbook=null;
	    excel.add(new ExcelBean("专业名称","major",0));
	    excel.add(new ExcelBean("人数","num",0));
	    map.put(0, excel);
	    String sheetName = VscienceExport;
	    xssfWorkbook = ExcelUtil.createExcelFile(Vscience.class, list, map, sheetName);
	    return xssfWorkbook;
	}
	
	/**
	 * 导出Excel		文科人数统计
	 * */
	public XSSFWorkbook VsciencesExportExcelInfo(String Vscience1Export) throws InvocationTargetException, ClassNotFoundException, IntrospectionException, ParseException, IllegalAccessException {  
		List<Vscience1> list= vscience1Mapper.selectAll();
	    List<ExcelBean> excel=new ArrayList<>();
	    Map<Integer,List<ExcelBean>> map=new LinkedHashMap<>();
	    XSSFWorkbook xssfWorkbook=null;
	    excel.add(new ExcelBean("专业名称","major",0));
	    excel.add(new ExcelBean("人数","num",0));
	    map.put(0, excel);
	    String sheetName = Vscience1Export;
	    xssfWorkbook = ExcelUtil.createExcelFile(Vscience1.class, list, map, sheetName);
	    return xssfWorkbook;
	}
}
